var tableid=new Object();
function setTableId(id){
    tableid=id;
}
function getTableId(){
    return tableid;
}
//添加ssxq和pcsdm两个参数
var map = new Object();
function setMap(obj){
	map.ssxq = obj.ssxq;
	map.pcsdm = obj.pcsdm;
}

var jlxmcwindow,mlphwindow;
function getJlxmcwindow(){
	return jlxmcwindow;
}
function getMlphwindow(){
	return mlphwindow;
}
function queryAddress(table){
	var action = urlpath + '/rk1305.baseplugin::/dzCommonModule/action/addressQueryAction.action' + "?xml=" + createFormXml(addRessQueryForm,'','addressCondition');
	table.select(action);
}

function addDzxx(table){
	var selectId = tree.getSelectedItemId();//
	var selectText = tree.getItemText(selectId);

	var level = tree.getLevel(selectId);
	jlxmcwindow = "";
	mlphwindow = "";
	if(level == "4"){
		var jlxdm = selectId;
		var jlxmc = selectText;
		jlxmcwindow = selectText;
		var param = "?jlxdm="+jlxdm+"&jlxmc="+jlxmc;
		
	}
	if(level == "5"){
		var jlxdm = tree.getParentId(selectId);
		var jlxmc = tree.getItemText(jlxdm);
		jlxmcwindow = tree.getItemText(jlxdm);
		var param = "?jlxdm="+jlxdm+"&jlxmc="+jlxmc;
	}
	if(level == "6"){
		var jlxdm = tree.getParentId(tree.getParentId(selectId));
		var jlxmc = tree.getItemText(jlxdm);
		jlxmcwindow = tree.getItemText(jlxdm);
		var mlph = tree.getItemText(selectId);
		mlphwindow = selectText;
		var param = "?jlxdm="+jlxdm+"&jlxmc="+jlxmc+"&mlph="+mlph;
	}

	
	if(param=="undefined"||param==null){
		param = "?jlxdm=&jlxmc=";
	}
	//alert(param);
	var action = urlpath + "/rk1305.baseplugin/dzCommonModule/page/dzxxInput.jsp"+param;
	
	var retval = window.showModalDialog(action,window, "dialogHeight: 420px; dialogWidth: 780px; edge: Sunken; center: Yes; help: No; resizable: Yes; status: No;");
	if(retval!=undefined){	
  		table.add(retval);
 	}	
 	
}
function cancelDzxx(table){	
if (!confirm('您确认要删除当前的数据吗？'))	return;
	
	var dzbmSelect = table.getValue("dzbm");		
	var action = urlpath + "/rk1305.baseplugin::/dzCommonModule/action/cancelDzxx.action?dzbmSelect=" + dzbmSelect;
	var param = "dzbmSelect=" + dzbmSelect;
      // alert(action);
       remoteCall(action,"post","",recallFlag);
}

function recallFlag(res){
  	if(res.success){
  		if(res.code=="warning"){
  		    var param = "xml="+xml+"&ywid=csrh";
  			opendiaWarn(res.text,action,param,recall);
  		}else{
  		   // alert(res.text);
  			//openModalDialog("<%=request.getContextPath()%>/cn.com.cchongda.saturn.rkxt/commonPage/print.jsp",null,550,220);
  			addressQueryList.remove();
  		}
  	}else{
  		openErrorDialog(res.text);
  	}
  }

function queryDzxxByDzbm(table){
	var dzbmSelect = table.getValue("dzbm");
	var action = urlpath + "/rk1305.baseplugin::/dzCommonModule/action/queryDzxxByDzbm.action?queryType=update&dzbm=" + dzbmSelect;
	var retval = window.showModalDialog(action,window, "dialogHeight: 420px; dialogWidth: 780px; edge: Sunken; center: Yes; help: No; resizable: Yes; status: No;");
	if(retval!=undefined){	
		table.remove();
  		table.add(retval);
 	}
}



//双击事件执行地址查询
function tonDbclick(id) {
	tree.selectItem(id);	
	var level = tree.getLevel(id);
	
	var dzbm = id;
	if(level == "6"){		
		var action = urlpath + "/rk1305.baseplugin::/dzCommonModule/action/queryDzxxByDzbm.action?queryType=tree&dzbm=" + dzbm;
		getTableId().select(action);		
	}
}
//单击"+"图标执行打开事件,执行查询
function tonOpenclick(id,mode){
	if(mode == "-1") {return true;}
	if(mode == "1") { tree.closeItem(id);return;}
	//var parentid = tree.getParentId(parentid);
	var level = tree.getLevel(id);
	if (mode == "0"){
		if(level==4){
			var param = "ssxq="+map.ssxq+"&pcsdm="+map.pcsdm+"&jlxdm=" + id;
			var action = urlpath + "/rk1305.baseplugin::/dzCommonModule/action/queryMlphTree.action";
			tree.loadFXML(action,encodeURI(param));
		}
		if(level=="5"){
			var jlxdm = tree.getParentId(id);
			var mlph = tree.getItemText(id);
			var param = "ssxq="+map.ssxq+"&pcsdm="+map.pcsdm;
			param = param + "&jlxdm="+jlxdm+"&id="+id+"&mlph="+mlph;
			var action = urlpath + "/rk1305.baseplugin::/dzCommonModule/action/queryMlxzTree.action";
			tree.loadFXML(action,encodeURI(param));
		}
	}
}

function tonclick(id){
	//alert("Item "+tree.getItemText(id)+" was selected");
	
	//var sID = tree.getSelectedItemId();//
	//alert(sID);	
	//alert(tree.getParentId(tree.getParentId(sID)));
	
	//alert("Item "+tree.getItemText(id)+" was selected");
	//treeSelectId = id;
	//treeSelectLevel = tree.getLevel(id);
	//treeSelectItem = tree.getItemText(id);
	//alert(tree.getparentId(tree.getParentId(id));
	
}
//初始化Tree进行查询
function initTree(treeId){   
	tree=new dhtmlXTreeObject(treeId,"100%","100%",0);
	var imagePath = "";
	tree.setImagePath(urlpath + "/edu.ccut.saturn.manager.bundles.impl/componentModule/page/js/rkxt/common/imgs/");
	var action = urlpath + "/rk1305.baseplugin::/dzCommonModule/action/queryDzxxTree.action";
	
	var param = "ssxq="+map.ssxq+"&pcsdm="+map.pcsdm;//"ssxq=610303&pcsdm=001";
	tree.setXMLAutoLoading(action);	
	tree.loadFXML(action,param);
	
	tree.setOnOpenHandler(tonOpenclick);
	tree.setOnClickHandler(tonclick);
	tree.setOnDblClickHandler(tonDbclick);
}	  
	  
